<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Requests\Api\v1\IncomeRequest;
use App\Http\Resources\AccountResource;
use App\Models\Account;
use App\Models\User;

class AccountController extends Controller
{
    public function index(IncomeRequest $request)
    {
        $user = User::getUser(['tiktokid'=>$request->header('Userid')]);
        $page = $request->get('page', 1);
        $limit = $request->get('limit', 10);
        $page = $this->paging($page, $limit);
        $date = $request->get('date','');
        $type = $request->has('type') && $request->get('type') >= 0 ? $request->get('type') : -1;
        $data =  AccountResource::collection((new Account())->getAccounts($user->id, $type, $page, $limit, $date));
        return $this->success($data);
    }

    //账变类型
    public function type()
    {
        $account_type = trans('validation.account_type');
        $keys = [2,3,7,8];
        $data = [];
        foreach ($account_type as $key=>$val){
            if(in_array($key,$keys)){
                $data[$key] = $val;
            }
        }
        return $this->success($data);
    }
}
